import thin_render from "../../../lib/thin_render.mjs";
import { nearest_data } from "../../../lib/nearest.mjs";
import { renderEditInput } from "../editors/input.mjs";
import { renderEditSelect } from "../editors/select.mjs";
import { renderEditTextarea } from "../editors/textarea.mjs";
import { renderEditUnderline } from "../editors/underline.mjs";

/**
 * 渲染编辑单元格
 * @param {Object} params - 渲染参数
 */
export function renderEditCell({ td, col, template, insert }) {
  if (typeof col.col === "object") {
    thin_render(td, col.col);
  } else if (typeof col.col === "function") {
    col.col({ container: td, data: nearest_data(td) });
  } else if (col.type === "checkbox" || col.type === "select") {
    renderEditSelect(td, col, template, insert);
  } else if (col.type === "textarea") {
    renderEditTextarea(td, col, template, insert);
  } else if (
    insert ||
    (!col.DateTimeFormat && !col.NumberFormat && !col.underline)
  ) {
    renderEditInput(td, col, template, insert);
  } else {
    renderEditUnderline(td, col, template);
  }
}
